package cn.tedu.ivos01.user.controller;

import cn.tedu.ivos01.base.response.JsonResult;
import cn.tedu.ivos01.user.pojo.dto.UserLoginParam;
import cn.tedu.ivos01.user.pojo.dto.UserQuery;
import cn.tedu.ivos01.user.pojo.dto.UserSaveParam;
import cn.tedu.ivos01.user.pojo.vo.UserVO;
import cn.tedu.ivos01.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "用户模块接口")
@Slf4j
@RestController
@RequestMapping("/v1/user")
public class UserController {
    @Autowired
    private UserService userService;

    @ApiOperation("用户登录功能")
    @GetMapping("/login")
    public JsonResult login(UserLoginParam userLoginParam){
        log.debug("用户注册参数:userLoginParam:{} ",userLoginParam);
        UserVO userVO = userService.login(userLoginParam);
        return JsonResult.ok(userVO);
    }

    @ApiOperation("新增用户功能")
    @PostMapping("/save")
    public JsonResult saveUser(UserSaveParam userSaveParam){
        log.debug("新增用户参数: userSaveParam : {} ",userSaveParam);
        userService.saveUser(userSaveParam);
        return JsonResult.ok();
    }

    @ApiOperation("查询用户功能")
    @GetMapping("/select")
    public JsonResult selectUser(UserQuery userQuery){
        log.debug("查询用户参数:userQuery : {}",userQuery);
        List<UserVO> list = userService.selectUser(userQuery);
        return JsonResult.ok(list);
    }

    @ApiOperation("重置密码功能")
    @PostMapping("/update/password/{userId}")
    public JsonResult resetPassword(@PathVariable Long userId){
        log.debug("重置密码参数: userId={}",userId);
        userService.resetPassword(userId);
        return JsonResult.ok();
    }

    @ApiOperation("删除用户功能")
    @PostMapping("/delete/{userId}")
    public JsonResult deleteUser(@PathVariable Long userId){
        log.debug("删除用户参数: userId ={}",userId);
        userService.deleteUser(userId);
        return JsonResult.ok();
    }


}
